<?php
namespace app\common\model;
require_once APP_PATH . '/../vendor/aliyunsms/TopSdk.php';
date_default_timezone_set('Asia/Shanghai'); 
class Sms extends Base
{
    protected function initialize()
    {
        parent::initialize();
    }
    public static function sendCode ($mobile='17521180599',$code='123456') {
        $c = new \TopClient;
        $c->appkey = config('alisms_appkey');
        $c->secretKey = config('alisms_appsecret');
        $req = new \AlibabaAliqinFcSmsNumSendRequest;
        $req->setExtend("123456");
        $req->setSmsType("normal");
        $req->setSmsFreeSignName(config('alisms_sign'));
        $json = json_encode([
            'code' => (string)$code,
            'product' => config('alisms_product')
        ]);
        $req->setSmsParam($json);
        $req->setRecNum($mobile);
        $req->setSmsTemplateCode(config('alisms_template'));
        $resp = $c->execute($req);
        $res = json_encode($resp);
        $res = json_decode($res,true);
        if($res['result']['err_code']==0) {
            return true;
        }else{
            return $res['result']['msg'];
        }
    }
} 